package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.ClothInspectionDto;
import com.pureut.production.domain.dto.DegreasDocumentDto;
import com.pureut.production.domain.dto.SpunlaceAndDegreasDto;
import com.pureut.production.domain.vo.*;
import com.pureut.production.service.DegreasDocumentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 脱脂制令单控制层
 */
@RestController
@RequestMapping("/degreas-document")
public class DegreasDocumentController extends BaseController {

    /**
     * 脱脂控制层service
     */
    @Resource
    DegreasDocumentService degreasDocumentService;

    /**
     * 脱脂制令单列表
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:list")
    @GetMapping("/list")
    public TableDataInfo degreasDocumentList(DegreasDocumentVo degreasDocumentVo) {
        startPage();
        // 脱脂制令单列表
        List<DegreasDocumentDto> list = degreasDocumentService.getList(degreasDocumentVo);
        return getDataTable(list);
    }

    /**
     * 脱脂制令单新增
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:add")
    @Log(title = "脱脂制令单新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addDegreas(@RequestBody DegreasDocumentVo degreasDocumentVo) throws Exception {
        return toAjax(degreasDocumentService.addDegreas(degreasDocumentVo));
    }

    /**
     * 修改
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:edit")
    @Log(title = "脱脂制令单修改", businessType = BusinessType.UPDATE)
    @PutMapping("/updateDegreas")
    public AjaxResult updateDegreas(@RequestBody DegreasDocumentVo degreasDocumentVo) {
        return toAjax(degreasDocumentService.updateDegreas(degreasDocumentVo));
    }

    /**
     * 上线
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:goOnline")
    @Log(title = "脱脂制令单上线", businessType = BusinessType.UPDATE)
    @GetMapping("/onLine/{id}")
    public AjaxResult onLine(@PathVariable("id") Long id) {
        return toAjax(degreasDocumentService.onLine(id));
    }

    /**
     * 停产
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:stop")
    @Log(title = "脱脂制令单停产", businessType = BusinessType.UPDATE)
    @GetMapping("/stop/{id}")
    public AjaxResult stop(@PathVariable("id") Long id) {
        return toAjax(degreasDocumentService.stop(id));
    }

    /**
     * 关结
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:close")
    @Log(title = "脱脂制令单关结", businessType = BusinessType.UPDATE)
    @PostMapping("/close")
    public AjaxResult close(@RequestBody CloseVo closeVo) throws Exception {
        return toAjax(degreasDocumentService.close(closeVo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:remove")
    @Log(title = "脱脂制令单删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteDegreasDocument/{id}")
    public AjaxResult deleteDegreasDocument(@PathVariable("id") Long id) {
        return toAjax(degreasDocumentService.deleteDegreasDocument(id));
    }

    /**
     * 查看
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degnproduc:query")
    @GetMapping("/queryDegreasDocument/{id}")
    public AjaxResult queryDegreasDocument(@PathVariable("id") Long id) {
        return AjaxResult.success(degreasDocumentService.queryDegreasDocument(id));
    }

    /**
     * 查询bom返回仓库数据及所需用量
     */
    @GetMapping("/queryBom")
    public AjaxResult queryBom(String materialCode, double planWeight, Long bomId, Long lineId) {
        return AjaxResult.success(degreasDocumentService.queryBom(materialCode, planWeight, bomId, lineId));
    }

    /**
     * 新增时获取预计完工时间和预计工时
     */
    @PostMapping("/getTimeAndWorkHours")
    public AjaxResult getTimeAndWorkHours(@RequestBody GetTimeAndWorkHoursVo getTimeAndWorkHoursVo) {
        return AjaxResult.success(degreasDocumentService.getTimeAndWorkHours(getTimeAndWorkHoursVo));
    }

    /**
     * 根据关联单号查询脱脂制令单信息
     */
    @PostMapping("/selectDegreasDocumentInfo")
    public AjaxResult selectDegreasDocumentInfo(String feedOrderNumber) {
        return AjaxResult.success(degreasDocumentService.selectDegreasDocumentInfo(feedOrderNumber));
    }

    /**
     * 获取生产中脱脂制令单列表(巡检单据查询调用)
     */
    @GetMapping("/getOutDegresDocument")
    public AjaxResult getOutDegresDocument(DegreasDocumentVo degreasDocumentVo) {
        return AjaxResult.success(degreasDocumentService.getOutDegresDocument(degreasDocumentVo));
    }

    /**
     * 水刺及脱脂制令单合并列表
     */
    @GetMapping("/getSpunlaceAndDegreasList")
    public TableDataInfo getSpunlaceAndDegreasList(SpunlaceAndDegreasVo spunlaceAndDegreasVo) {
        startPage();
        // 脱脂制令单列表
        List<SpunlaceAndDegreasDto> list = degreasDocumentService.getSpunlaceAndDegreasList(spunlaceAndDegreasVo);
        return getDataTable(list);
    }
}
